package top.yangyitao.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import top.yangyitao.entity.OrganizationRole;
import top.yangyitao.entity.User;
import top.yangyitao.entityEnum.UserStatusEnum;
import top.yangyitao.entityEnum.UserWorkStatusEnum;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class UserDto{
	
	long id;
	String username;
	String headImg;
	String nickname;
	Integer status;
	String statusName;
	Integer workStatus;
	String workStatusName;
	RoleDto role = new RoleDto();
	OrganizationDto organization = new OrganizationDto();
	OrganizationRoleDto organizationRole;
	public UserDto convert(User user) {
		setUsername(user.getUsername());
		setNickname(user.getNickname());
		setId(user.getId());
		setHeadImg(user.getHeadImg());
		setStatus(user.getStatus());
		setStatusName(UserStatusEnum.values()[user.getStatus()].getName());
		setWorkStatus(user.getWorkStatus());
		setWorkStatusName(UserWorkStatusEnum.values()[user.getWorkStatus()].getName());
		setRole(role.convert(user.getRole()));
		setOrganization(organization.convert(user.getOrganization()));
		OrganizationRole organizationRole = user.getOrganizationRole();
		if(organizationRole!=null) {
			setOrganizationRole(new OrganizationRoleDto().convert(organizationRole));
		}
		return this;
	}
	
}
